// 使用MySQL连接而不是SQLite
const db = require('./Config/database.js');
const bcrypt = require('bcrypt');
const saltRounds = 12;

// 添加测试用户
const users = [
  { username: '张三', phone: '13800138001', password: 'password1' },
  { username: '李四', phone: '13800138002', password: 'password2' },
  { username: '王五', phone: '13800138003', password: 'password3' },
  { username: '赵六', phone: '13800138004', password: 'password4' },
  { username: '钱七', phone: '13800138005', password: 'password5' }
];

// 哈希密码并插入用户
async function insertTestUsers() {
  try {
    for (const user of users) {
      // 哈希密码
      const hashedPassword = await bcrypt.hash(user.password, saltRounds);
      
      // 插入用户到MySQL数据库
      await db.execute(
        'INSERT INTO user (username, phone, password) VALUES (?, ?, ?)',
        [user.username, user.phone, hashedPassword]
      );
      
      console.log(`用户 ${user.username} 已添加到MySQL数据库`);
    }
    
    console.log('所有测试用户添加完成');
    // 关闭数据库连接
    process.exit(0);
  } catch (error) {
    console.error('添加用户失败:', error.message);
    process.exit(1);
  }
}

// 执行添加用户操作
insertTestUsers();